<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
    <meta http-equiv="expires" content="0">
    <title>领取奖品</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
<div class="container" style="margin-top: 60px;">
    <form class="form-horizontal" id="myForm">
        <div class="form-group">
            <label for="username" class="col-sm-2 control-label">收货人</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="username" id="username" placeholder="收货人">
            </div>
        </div>
        <div class="form-group">
            <label for="phone" class="col-sm-2 control-label">手机号</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="phone" id="phone" placeholder="手机号">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">省市区</label>
            <div class="col-sm-10">
                <div class="form-group">
                    <div class="col-sm-3">
                        <select name="input_province" id="input_province" class="form-control" >
                            <option value="">--请选择--</option>
                        </select>
                    </div>
                    <div class="col-sm-3">
                        <select name="input_city" id="input_city" class="form-control">
                            <option value="">--请选择--</option>
                        </select>
                    </div>
                    <div class="col-sm-3">
                        <select name="input_area" id="input_area" class="form-control">
                            <option value="">--请选择--</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="address" class="col-sm-2 control-label">配送地址</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="address" id="address" placeholder="详细地址">
            </div>
        </div>
        <div class="form-group">
            <label for="postalCode" class="col-sm-2 control-label">邮政编码</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="postalCode" id="postalCode" placeholder="邮政编码">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-success" style="width: 100%;" id="submit">提交</button>
            </div>
        </div>
    </form>
</div>
<script src="js/jquery.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script src="js/sha1.js"></script>
<script src="js/address.js"></script>
<script src="js/config.js"></script>
<script src="js/public2.js"></script>
<script type="text/javascript">
    let act_id = getQueryVariable('act_id');
    if(!act_id){
        alert('未传参数');
        location.replace('./index.html');
    }
    function afterVerify(){
        //验证是否中奖
        $.post(baseUrl+'client/receive/check',{
            act_id:act_id,
        },function(result){
            if(result.code === -1){
                alert(result.msg);
                location.replace('./index.html');
            }
        },'json');
    }
    $(function () {
        var html = "";
        $("#input_city").append(html);
        $("#input_area").append(html);
        $.each(pdata,function(idx,item){
            if (parseInt(item.level) == 0) {
                html += "<option value="+item.code+" >"+ item.names +"</option> ";
            }
        });
        $("#input_province").append(html);

        $("#input_province").change(function(){
            if ($(this).val() == "") return;
            $("#input_city option").remove();
            $("#input_area option").remove();
            //var code = $(this).find("option:selected").attr("exid");
            var code = $(this).find("option:selected").val();
            code = code.substring(0,2);
            var html = "<option value=''>--请选择--</option>";
            $("#input_area option").append(html);
            $.each(pdata,function(idx,item){
                if (parseInt(item.level) == 1 && code == item.code.substring(0,2)) {
                    html +="<option value="+item.code+" >"+ item.names +"</option> ";
                }
            });
            $("#input_city ").append(html);
        });

        $("#input_city").change(function(){
            if ($(this).val() == "") return;
            $("#input_area option").remove();
            var code = $(this).find("option:selected").val();
            code = code.substring(0,4);
            var html = "<option value=''>--请选择--</option>";
            $.each(pdata,function(idx,item){
                if (parseInt(item.level) == 2 && code == item.code.substring(0,4)) {
                    html +="<option value="+item.code+" >"+ item.names +"</option> ";
                }
            });
            $("#input_area ").append(html);
        });
    });
    $(window).load(function() {

        $('#submit').click(function(){

            var form = {};
            var t = $('#myForm').serializeArray();
            $.each(t, function() {
                form[this.name] = this.value;
            });

            if(!form.username){
                alert('收货人必填');
                return;
            }
            if(!form.phone){
                alert('手机号必填');
                return;
            }
            if(!form.input_province || !form.input_city || !form.input_area){
                alert('省市区必填');
                return;
            }
            if(!form.address){
                alert('地址必填');
                return;
            }
            if(!form.postalCode){
                alert('邮政编码必填');
                return;
            }
            if(form.postalCode.length !== 6){
                alert('请填写6位邮编');
                return;
            }

            //验证完成,提交表单
            $.post(baseUrl+'client/receive',{
                act_id:act_id,
                username:form.username,
                phone:form.phone,
                province:form.input_province,
                city:form.input_city,
                district:form.input_area,
                address:form.address,
                postalCode:form.postalCode,
            },function(result){
                if(result.code === 0){
                    alert(result.msg);
                    window.history.back(-1);
                }else{
                    alert(result.msg);
                }
            },'json');


        });
    })

</script>
<script src="js/verify.js"></script>
</body>
</html>
